package com.cqut.forum.dao.imp;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.cqut.forum.dao.RoleDao;
import com.cqut.forum.entity.Role;

@Component
public class RoleDaoImp extends BaseDaoImp implements RoleDao{
	
	@Resource
	private HibernateTemplate hibernateTemplate;

	public <T> boolean unDelete(int id) {
		return false;
	}

	@SuppressWarnings("unchecked")
	public Role getRole(String roleName) {
		String hql = "select r from Role r where roleName = ?";
		Query query = super.getQuery(hql);
		query.setString(0, roleName);
		
		List<Role> roles = query.list();
		
		if(roles.size()==0){
			return null;
		}
		else
			return roles.get(0);
	}
	
	/**********get and set method****************/
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> getAllRole() {
		String sql = "select r.role_id,r.role_name from role r";
		List<Map<String, Object>> roles = (List<Map<String, Object>>) super.excuteSql(sql, null, null);
		return roles;
	}
}
